<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="/struts-tags" prefix="s"%>
<%String path= "http://"+request.getHeader("host")+request.getContextPath(); %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<link href="skin/2011/base.extraction.css" type="text/css" rel="stylesheet"/>
</head>
<script src="js/jQuery.js" type="text/javascript"></script>
<SCRIPT type="text/javascript">
function submitForm() {
	
	var username = $('#Name').val();
	var password = $('#Password').val();
	var tOrb = $("input[@type=radio][@checked]").val();;
	var group = $('#group').val();
	var url ="<%=path %>"+"/loginByAjax.action";
	$.post(url,{'username':username,'password':password,'tOrb':tOrb,'group':group},function(result){
		if(result==''||result=='null') {
			alert("用户名或密码错误！");
		}else {
			$('form[name=form1]').attr('action',result);
			$('form[name=form1]').submit();
		}
	    });
}
function clearSel(oSelect){
	while(oSelect.childNodes.length>0){
		oSelect.removeChild(oSelect.childNodes[0]);
	}
}
window.onload= function() {
	getGroup();
}
function getGroup() {
	var group = document.getElementById("group");
	clearSel(group);
	 //清空项目
	var username = document.getElementById("Name").value;
	var url ="<%=path %>"+"/getGroupByAjax.action?username="+username;
   	$.ajax({
       	url: url,
       	dataObject: {"username":username},
      	dataType: 'text',
      	type: "post",
       	success: function(result) {
   			var arr = result.split(',');
   			setGroup(arr);
       	}
   });
}
function setGroup(result){
	var group = document.getElementById("group");
	$.each(result, function(i, area){
		var value = area;
		var text = area;
		var option = new Option(text,value);
		group.options.add(option);
	});
	
}
</SCRIPT>
<body  bgcolor="lightgray">
<form name="form1" method="post" action="" id="form1">
<div class="w">
	<div class="login m">
		<div class="mt">
			京东抽包系统登录
		</div>
		<div class="mc">
			<div class="item">
				<div class="tit">用户名：</div>
				<div class="i-item">
					<input name="username" type="text" id="Name"  class="text" value="" onblur="getGroup()" />
				</div>
			</div>
			<div class="item">
				<div class="tit">
					密码：
				</div>
				<div class="i-item">
					<input name="password" type="password" id="Password" class="text" value="" />
				</div>
			</div>
			<div class="item">
				<div class="tit">
					组别：
				</div>
				<div class="i-item">
					<select name="group" id="group" class="chose">
						<option value="" selected>请选择组别</option>
					</select>
				</div>
			</div>
			<div class="item">
				<div class="tit">
					主干/分支：
				</div>
				<div class="i-item">
					<input type="radio" id="tOrb1" name="tOrb" value="t" checked="checked" /><label for="tOrb1"><font style="font-size: 16px">主干</font></label>
                    <input type="radio" id="tOrb2" name="tOrb" value="b" /><label for="tOrb2"><font style="font-size: 16px">分支</font></label>

				</div>
			</div>
			<div class="btn">
				<input type="button" name="Logon" value="" id="Logon" onclick="submitForm()" tabindex="3" class="submit" />
			</div>
		</div>
	</div>
</div>
    </form>


</body>
</html>